#include "task.h"
static DATA data = {0};
/*===============DATA===============*/
void Data_Num_to_Str(void)
{
	rt_sprintf((char *)data.send_data,"%ld,%ld,%ld,%ld",data.key_rocker_data[0],data.key_rocker_data[1],
	data.key_rocker_data[2],data.key_rocker_data[3]);
}

/*===============LCD===============*/
static LCD_CONTROL LCD;
void LCD_CTRL_Init()
{
	LCD.lcd_tid = RT_NULL;
	LCD.lcd_buff = 1024*5;
	LCD.lcd_param = RT_NULL;
	LCD.lcd_priority = 5;
	LCD.lcd_tick = 20;
}

rt_err_t LCD_TASK_Init()
{
	LCD_CTRL_Init();
//	LCD_Init(0);
	LCD.lcd_tid = rt_thread_create("LCD",LCD_TASK_Entry,LCD.lcd_param,
									LCD.lcd_buff,LCD.lcd_priority,LCD.lcd_tick);
	if(LCD.lcd_tid == RT_NULL)
	{
		rt_kprintf("lcd thread init err");
		return RT_ERROR;
	}
	rt_thread_startup(LCD.lcd_tid);
}

void LCD_TASK_Entry(void * param)
{
	lv_init();
	lv_port_disp_init();
	lv_port_indev_init();
	lv_demo_stress();
//	lv_demo_music();
	
//	lv_obj_t * switch_obj = lv_switch_create(lv_scr_act());
//	lv_obj_set_size(switch_obj,120,60);
//	lv_obj_align(switch_obj,LV_ALIGN_CENTER,0,0);
	

	while(1)
	{
		lv_timer_handler();

		rt_thread_mdelay(5);
	}
}

/*===============KEY===============*/
static KEY_CONTROL KEY;
void KEY_CTRL_Init(void)
{
	KEY.key_tid = RT_NULL;
	KEY.key_buff = 512;
	KEY.key_param = RT_NULL;
	KEY.key_priority = 10;
	KEY.key_tick = 20;
}
rt_err_t KEY_TASK_Init(void)
{
	KEY_CTRL_Init();
	KEY.key_tid = rt_thread_create("KEY",KEY_TASK_Entry,KEY.key_param,
									KEY.key_buff,KEY.key_priority,KEY.key_tick);
	if(KEY.key_tid == RT_NULL)
	{
		rt_kprintf("key thread init err");
		return RT_ERROR;
	}
	rt_thread_startup(KEY.key_tid);
}
void KEY_TASK_Entry(void * param)
{
	
	while(1)
	{
	  HAL_ADC_Start_DMA(&hadc1,(uint32_t *)data.key_rocker_data,sizeof(data.key_rocker_data));
	  rt_thread_mdelay(10);
	}
}

